package com.exsun.gateway.jt809.start;

import com.exsun.gateway.jt809.slave.JT809Server;
import com.exsun.gateway.jt809.config.NettyServerConfig;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class SlaveListener implements ApplicationListener<ApplicationReadyEvent> {
	private final static Logger logger = Logger.getLogger(SlaveListener.class);
	@Autowired
	private JT809Server jt809Server;
	@Autowired
	private NettyServerConfig nettyServerConfig;
	@Override
	public void onApplicationEvent(final ApplicationReadyEvent event) {

		logger.info("启动本地监听，端口：" + nettyServerConfig.getNettyPort());
		try {
			jt809Server.bind(nettyServerConfig.getNettyPort());// 启动tcp服务端监听
		} catch (Exception e) {
			logger.error("-----Listener Error-----");
			e.printStackTrace();
		}
	}

}